from rest_framework import serializers

from goods.models import SKU
from orders.models import OrderInfo,OrderGoods





# 1.订单信息序列化器
class OrderViewSetSerializer(serializers.ModelSerializer):
    class Meta:
        model = OrderInfo
        fields = "__all__"

class SKUModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = SKU
        fields = ("name","default_image_url")

# 2.订单.订单商品,商品的序列化器
class OrderGoodsModleSerializer(serializers.ModelSerializer):

    # 1.重写sku
    sku = SKUModelSerializer(read_only=True)


    class Meta:
        model = OrderGoods
        fields = ("sku","price","count")


class OrdersModelSerializer(serializers.ModelSerializer):
    # 1.重写skus,实际就是订单商品
    skus = OrderGoodsModleSerializer(read_only=True,many=True)


    class Meta:
        model = OrderInfo
        # fields = ("order_id","status","create_time",
        #           "user","total_count",
        #           "freight","pay_method","skus")
        fields = "__all__"
